﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;

namespace Hi_Baidu.Entry
{
    /// <summary>
    ///     分组集合类
    /// </summary>
    public class ItemCollection : ICollectionManager
    {
        /// <summary>
        ///     成员集合
        /// </summary>
        public Hashtable Members = null;

        public ItemCollection()
        {
            if (Members == null)
            {
                Members = new Hashtable();
            }
        }

        #region ICollectionManager 成员

        public bool Add(IMetaData CollectionMember)
        {
            if (Members[CollectionMember.Key] == null)
            {
                Members.Add(CollectionMember.Key, CollectionMember);
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool Remove(IMetaData CollectionMember)
        {
            if (Members[CollectionMember.Key] != null)
            {
                Members.Remove(CollectionMember.Key);
                return true;
            }
            else
            {
                return false;
            }
        }

        public bool Remove(string Key)
        {
            if (Members[Key] != null)
            {
                Members.Remove(Key);
                return true;
            }
            else
            {
                return false;
            }
        }

        public IMetaData GetMemberByKey(string Key)
        {
            return (IMetaData)Members[Key];
        }

        public int Count()
        {
            return Members.Count;
        }

        #endregion

        #region IMetaData 成员

        private String key;
        public string Key
        {
            get
            {
                return key;
            }
            set
            {
                key = value;
            }
        }

        #endregion
    }
}
